package components;

import bean.GuaMap;

import javax.swing.*;
import java.awt.*;

public class MyPanel8 extends JPanel {

    private final String binary;
    private final DataFactory dataFactory = DataFactory.getInstance();
    public MyPanel8(String binary){
        this.binary = binary;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        char[] chars = binary.toCharArray();
        int y = 25;
        for (char c : chars) {
            if (c == 48) {
                g.setColor(Color.black);
                g.drawRect(25, y, 35, 10);
                g.fillRect(25, y, 35, 10);
                g.drawRect(70, y, 35, 10);
                g.fillRect(70, y, 35, 10);
            } else if (c == 49) {
                g.setColor(Color.red);
                g.drawRect(25, y, 80, 10);
                g.fillRect(25, y, 80, 10);
            }
            g.setColor(Color.black);
            GuaMap.Gua gua = dataFactory.getGuaMap().get(binary);
            g.drawString(gua.getTop(),57,15);
            g.drawString(gua.getBottom(),57,105);
            y += 25;
        }
    }
}
